package com.right.health.app.ui.main.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.right.health.app.R;
import com.right.health.app.base.BasePresenterFragment;
import com.right.health.app.bean.HomeItem;
import com.right.health.app.common.DataCommon;
import com.right.health.app.ui.household.BloodPressureActivity;
import com.right.health.app.ui.household.BloodSugarActivity;
import com.right.health.app.ui.household.HeightWeightActivity;
import com.right.health.app.ui.main.adapter.HouseholdFeature1Adapter;
import com.right.health.app.widget.GridViewEx;

/*
 * 居家
 * Created by hopeliao on 2019-09-23
 *
 */
public class HouseholdFragment extends BasePresenterFragment {

    private HouseholdFeature1Adapter mFeatureAdapter1, mFeatureAdapter2;

    @Override
    public View onCreateView(LayoutInflater layoutInflater, ViewGroup viewGroup, Bundle bundle, String s) {
        return layoutInflater.inflate(R.layout.household, viewGroup, false);
    }

    @Override
    public void findView() {
        GridViewEx featureGrid1 = (GridViewEx) findViewById(R.id.feature_grid1);
        mFeatureAdapter1 = new HouseholdFeature1Adapter(getActivity());
        featureGrid1.setAdapter(mFeatureAdapter1);
        featureGrid1.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                HomeItem homeItem = (HomeItem)parent.getItemAtPosition(position);
                if(homeItem != null) {
                    switch (homeItem.name) {
                        case "血压":
                            startIntent(BloodPressureActivity.class);
                            break;
                        case "血糖":
                            startIntent(BloodSugarActivity.class);
                            break;
                        case "身高体重":
                            startIntent(HeightWeightActivity.class);
                            break;
                    }
                }
            }
        });

        GridViewEx featureGrid2 = (GridViewEx) findViewById(R.id.feature_grid2);
        mFeatureAdapter2   = new HouseholdFeature1Adapter(getActivity());
        featureGrid2.setAdapter(mFeatureAdapter2);
    }

    @Override
    public void initialize() {
        mFeatureAdapter1.setDataSource(DataCommon.getHouseholdFeature1());
        mFeatureAdapter2.setDataSource(DataCommon.getHouseholdFeature2());
    }
}
